package libcore.net.core;

import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;

/**
 * OkHttp Creator
 * Created by jaaksi on 2017/4/29.
 */
public abstract class BaseOkHttpCreator {

  private static final long TIMEOUT_CONNECT = 15 * 1000;

  public OkHttpClient create() {
    return createBuilder().build();
  }

  public OkHttpClient.Builder createBuilder() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(TIMEOUT_CONNECT, TimeUnit.MILLISECONDS);
    builder.readTimeout(TIMEOUT_CONNECT, TimeUnit.MILLISECONDS);
    builder.writeTimeout(TIMEOUT_CONNECT, TimeUnit.MILLISECONDS);
    //if (LibConfig.sIsDebug) {
    //  HttpLoggingInterceptor loggingInterceptor = HttpLoggingInterceptor.createLoggingInterceptor()
    //    .setLevel(HttpLoggingInterceptor.Level.BODY);
    //  builder.addInterceptor(loggingInterceptor);
    //}
    builder = customize(builder);
    return builder;
  }

  /**
   * @param builder
   * @return
   */
  public abstract OkHttpClient.Builder customize(OkHttpClient.Builder builder);
}
